import './sequelize/index'
import fetch from "node-fetch";
import {globalHeader} from "./config/gloabal";
import {buildFanCidyData, buildFanData, buildXhsUserLinkQiangua, exportQueryfans, fetchXiaohongshu, login, runBloggerData, runCron, runSheetBloggerData} from "./module/xiaohongshu/fetchXiaohongshu";
import xlsx from "xlsx";
import XLSX from "xlsx";
import {writeExcel} from "./excel/excel";
import {exportSubjectQueryfans, fetchBloggerDetail, fetchData, fetchNoteContent} from "./module/xiaohongshu/subject";
import {XhssubjectModel} from "./model/XhssubjectModel";
import {sortBy} from "lodash";


(async ()=>{
  //  await runCron();
  //await fetchXiaohongshu();
   //await buildXhsUserLinkQiangua();
    //await runBloggerData();
   // await exportQueryfans();
    await buildFanData();
   // await fetchNoteContent();
   // await fetchData(1);
  //await exportSubjectQueryfans();
    //await fetchBloggerDetail();
   // const row = await XhssubjectModel.findOne({where: {id: 1}})
    //console.log(row.noteContent)
   //await buildFanCidyData();
   // await runSheetBloggerData();
})()
/*
ALTER TABLE `xiaohongshu`
ADD COLUMN `blogger_id` varchar(200),
    ADD COLUMN `blogger_id_key` varchar(200),
    ADD COLUMN `is_fetch_data` tinyint(1) NOT NULL DEFAULT 0,
    ADD COLUMN `is_exception` tinyint(1) NOT NULL DEFAULT 0,
    ADD COLUMN `id` int NOT NULL AUTO_INCREMENT AFTER `is_exception`,
    ADD PRIMARY KEY (`id`);
ADD COLUMN `redid` varchar(100)
 */
async function getRedirectedUrl(url) {
    const response = await fetch(url, { method: 'HEAD',headers:{
            'User-Agent':
                'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
        },redirect:'follow' });
    console.log(response.headers)
    const redirectedUrl = response.headers.get('location');
    return redirectedUrl;
}

// const originalUrl = 'https://v.douyin.com/i8UT1MnH/';
// getRedirectedUrl(originalUrl)
//     .then(redirectedUrl => {
//         console.log('跳转后的URL地址：', redirectedUrl);
//     })
//     .catch(error => {
//         console.error('发生错误：', error);
//     });
